﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace MixingStation
{
    public delegate void m_messagecallback(IntPtr hHandle, int wParam, int lParam, IntPtr context);
    public enum PTZ_COMMAND
    {
        PTZ_LEFT = 0,
        PTZ_RIGHT = 1,
        PTZ_UP = 2,
        PTZ_DOWN = 3,
        PTZ_IRISADD = 4,
        PTZ_IRISDEC = 5,
        PTZ_FOCUSADD = 6,
        PTZ_FOCUSDEC = 7,
        PTZ_ZOOMADD = 8,
        PTZ_ZOOMDEC = 9,
        PTZ_GOTOPOINT = 10,
        PTZ_SETPOINT = 11,
        PTZ_AUTO = 12,
        PTZ_STOP = 13,
        PTZ_LEFTSTOP = 14,
        PTZ_RIGHTSTOP = 15,
        PTZ_UPSTOP = 16,
        PTZ_DOWNSTOP = 17,
        PTZ_IRISADDSTOP = 18,
        PTZ_IRISDECSTOP = 19,
        PTZ_FOCUSADDSTOP = 20,
        PTZ_FOCUSDECSTOP = 21,
        PTZ_ZOOMADDSTOP = 22,
        PTZ_ZOOMDECSTOP = 23,
        PTZ_LIGHT = 24,
        PTZ_LIGHTSTOP = 25,
        PTZ_RAIN = 26,
        PTZ_RAINSTOP = 27,
        PTZ_TRACK = 28,
        PTZ_TRACKSTOP = 29,
        PTZ_DEVOPEN = 30,
        PTZ_DECCLOSE = 31,
        PTZ_AUTOSTOP = 32,
        PTZ_CLEARPOINT = 33,
        PTZ_LEFTUP = 200,
        PTZ_LEFTUPSTOP = 201,
        PTZ_RIGHTUP = 202,
        PTZ_RIGHTUPSTOP = 203,
        PTZ_LEFTDOWN = 204,
        PTZ_LEFTDOWNSTOP = 205,
        PTZ_RIGHTDOWN = 206,
        PTZ_RIGHTDOWNSTOP = 207,
    };

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public struct CHANNEL_CLIENTINFO
    {

        [MarshalAsAttribute(UnmanagedType.LPStr)]
        public string m_sername;                    //server name

        [MarshalAsAttribute(UnmanagedType.LPStr)]
        public string m_username;                   //user name

        [MarshalAsAttribute(UnmanagedType.LPStr)]
        public string m_password;                   //password

        public ushort m_tranType;                    //transmit type   
        public ushort m_playstart;                   //is start view
        public byte m_ch;                            //channel
        public IntPtr m_hVideohWnd;                  //video wnd handle
        public IntPtr m_hChMsgWnd;                   //message wnd handle
        public uint m_nChmsgid;                      //message id  
        public int m_buffnum;                        //buff num
        public int m_useoverlay;                     //is use overlay
        public int nColorKey;                       //color key(reserved)

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
        public string url;                           //url
        //public delegate void IpCameraEventHandler(Int32 handle, int wParam, int lparam, IntPtr context);
        [MarshalAs(UnmanagedType.FunctionPtr)]
        public m_messagecallback callback;
        IntPtr context;

        //void (WINAPI *m_messagecallback)(LONG hHandle,int wParam,int lParam,void *context); //message callback function
        //	void *context;                      //message callback context
    };
    public class LauInterop
    {

        // CNET_APIIMPORT LONG  __stdcall VSNET_ClientStart(char *m_url,CHANNEL_CLIENTINFO *m_pChaninfo,WORD wserport = 3000,int streamtype = 0);       
        [DllImport("NetClient.dll")]
        public static extern Int32 VSNET_ClientStart([MarshalAs(UnmanagedType.LPStr)]string url,
             IntPtr info, short port, short streamtype);

        //CNET_APIIMPORT BOOL	 __stdcall VSNET_ClientPTZCtrl(LONG hHandle,int type,int value,int priority = 0, char *extrabuff = NULL, int extrasize = 0);
        [DllImport("NetClient.dll")]
        public static extern int VSNET_ClientPTZCtrl(Int32 handle, int type, int value, int priority, IntPtr extrabuff, int extrasize);
        //,  [MarshalAs(UnmanagedType.LPStr)]string extrabuff, int extrasize);

        //CNET_APIIMPORT BOOL  __stdcall VSNET_ClientStop(LONG hHandle);
        [DllImport("NetClient.dll")]
        public static extern int VSNET_ClientStop(Int32 handle);

        //CNET_APIIMPORT LONG  __stdcall VSNET_ClientGetState(LONG hHandle);
        [DllImport("NetClient.dll")]
        public static extern Int32 VSNET_ClientGetState(Int32 handle);

        //CNET_APIIMPORT BOOL  __stdcall VSNET_ClientStartup(UINT m_nMessage,HWND m_hWnd,void 
        //(WINAPI *m_messagecallback)(LONG hHandle,int wParam,INT_PTR lParam,void *context) = NULL,void *context = NULL, char *key = NULL);
        [DllImport("NetClient.dll")]
        public static extern bool VSNET_ClientStartup(uint m_nMessage, IntPtr m_hWnd, m_messagecallback collback, IntPtr conntex, IntPtr key);

        //CNET_APIIMPORT BOOL  __stdcall VSNET_ClientCleanup();
        [DllImport("NetClient.dll")]
        public static extern bool VSNET_ClientCleanup();
    }
}
